//精准计算

function acction(arg1, arg2, noLimit){
  this.arg1 = arg1 == '' ? 0 : parseFloat(arg1)
  this.arg2 = arg2 == '' ? 0 : parseFloat(arg2)
  this.noLimit = noLimit
  return this
}
acction.prototype = {
  tofide:function(str){
    if (String(str).indexOf(".") > -1) {
      if (str.toString().split(".")[1].length > 2) {
        return str.toFixed(2)
      } else {
        return str
      }
    } else {
      return str
    }
  },
  accAdd: function() {
    var r1, r2, m
    try {
      r1 = this.arg1.toString().split(".")[1].length
    } catch (e) {
      r1 = 0
    }
    try {
      r2 = this.arg2.toString().split(".")[1].length
    } catch (e) {
      r2 = 0
    }
    m = Math.pow(10, Math.max(r1, r2))
    return this.noLimit ? (this.arg1 * m + this.arg2 * m) / m : this.tofide((this.arg1 * m + this.arg2 * m) / m)
  },
  accSub: function(){
    var r1, r2, m
    try {
      r1 = this.arg1.toString().split(".")[1].length
    } catch (e) {
      r1 = 0
    }
    try {
      r2 = this.arg2.toString().split(".")[1].length
    } catch (e) {
      r2 = 0
    }
    m = Math.pow(10, Math.max(r1, r2))
    return this.noLimit ? (this.arg1 * m - this.arg2 * m) / m: this.tofide((this.arg1 * m - this.arg2 * m) / m)
  },
  accMul: function(){
    var m = 0, s1 = this.arg1.toString(), s2 = this.arg2.toString()
    try {
      m += s1.split(".")[1].length
    } catch (e) {
    }
    try {
      m += s2.split(".")[1].length
    } catch (e) {
    }
    return this.noLimit ? Number(s1.replace(".", "")) * Number(s2.replace(".", "")) / Math.pow(10, m) : this.tofide(Number(s1.replace(".", "")) * Number(s2.replace(".", "")) / Math.pow(10, m))
  },
  accDiv: function(){
    var t1 = 0, t2 = 0, r1, r2
    try {
      t1 = this.arg1.toString().split(".")[1].length
    } catch (e) {

    }
    try {
      t2 = this.arg2.toString().split(".")[1].length
    } catch (e) {

    }
    //return tofide(Number(s1.replace(".", "")) * Number(s2.replace(".", "")) / Math.pow(10, m))
    r1 = Number(this.arg1.toString().replace(".", ""))
    r2 = Number(this.arg2.toString().replace(".", ""))
    return this.noLimit ? (r1 / r2) * Math.pow(10, t2 - t1) : this.tofide((r1 / r2) * Math.pow(10, t2 - t1))
  }
}
module.exports = acction;
